<template>
<Row class="layout-content-body">
  <dtable :columns="columns" :dataAll="dataAll" inst
  :totals="total" @refresh="getall()" 
  @getflow="getflow" @edit="edit"  :loading="loading"></dtable>
  <Modal title="采购单信息" v-model="editData" :mask-closable="false" class="editm">
    <Form ref="editForm" :model="formItem" :label-width="80" :rules="ruleValidate">
      <Form-item label="名称" prop="Name">
        <Input v-model="formItem.Name" placeholder="请输入" :disabled="addid"></Input>
      </Form-item>
      <Form-item label="数量" prop="Count">
        <Input v-model="formItem.Count" number placeholder="请输入"></Input>
      </Form-item>
      <Form-item label="金额" prop="Money">
        <Input v-model="formItem.Money" number placeholder="请输入"></Input>
      </Form-item>
    </Form>
  </Modal>
</Row>
</template>

<script>
import {
  timeFormat, currency
} from '@/common/filter'
import dtable from '../../components/table/dtable.vue' //采用biztable
export default {
  data() {
    return {
      loading: false, //数据刷新遮罩层
      columns: [
        //多选框
        {
          title: '名称',
          key: 'Name',
          sortable: true
        },
        {
          title: '供应商',
          key: 'PartName',
          sortable: true
        },
        {
          title: '金额',
          key: 'Price',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', currency(params.row.Price,"￥"))
            ]);
          }
        },
        {
          title: '说明',
          key: 'Remark',
          sortable: true,
        },
        {
          title: '责任人',
          key: 'Creater',
          sortable: true
        },
        {
          title: '创建时间',
          key: 'Ctime',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', timeFormat(params.row.Ctime))
            ]);
          }
        },

      ], //表格样式
      dataAll: [], //表格数据来源
      dataShow: true, //是否显示表格数据查看表单
      editData: false, //显示编辑表单
      formItem: {
        Name: '',
        Count: 1,
        Money: 0
      }, //数据编辑表单
      ruleValidate: {
        Name: [{
          required: true,
          message: '账号不能为空',
          trigger: 'blur'
        }],
        Pname: [{
          required: true,
          message: '名称不能为空',
          trigger: 'blur'
        }, ],
      }, //数据编辑表单验证规则
      addid: true, //true为修改模式，false为添加模式
      role: [],
      org: [],
      total: 0
    }
  },
  components: {
    dtable,
  },
  computed: {


  },
  watch: {},
  methods: {
    getall() {
      this.loading = true
      let data={
        busyName:"yjk_buy"
      }
      this.$api.getAssetsbuyCompleted(data).then(res => {
        if (!res.error) {
          console.log(res.Data)
          this.dataAll = res.Data
          if(this.total){
            this.total = (res.Data).length
          }
        } else {
          this.$Message.error(res.message)
        }
      })
      setTimeout(() => {
        this.loading = false;
      }, 500);
    },
    edit(index) {
      //  console.log(index)
      this.addid = true
      this.formItem = index
      this.editData = true
    },
    getflow(index) {
      this.$router.push({
        name: '流程实例',
        params: {
          id: index.Id
        }
      })
    },




  },
  mounted() {
    this.getall()
  }
}
</script>
